package com.ltkj.ticket.controller;

import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.web.page.TableDataInfo;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.ticket.domain.TicVenuesPeriod;
import com.ltkj.ticket.service.ITicVenuesPeriodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 方案时间段Controller
 * 
 * @author ruoyi
 * @date 2023-08-30
 */
@Api(tags = "方案时间段")
@RestController
@RequestMapping("/period")
public class TicVenuesPeriodController extends BaseController
{
    @Autowired
    private ITicVenuesPeriodService ticVenuesPeriodService;

    /**
     * 查询方案时间段列表
     */
    @ApiOperation("查询方案时间段列表")
    @RequiresPermissions("ticket:period:list")
    @GetMapping("/list")
    public TableDataInfo list(TicVenuesPeriod ticVenuesPeriod)
    {
        startPage();
        List<TicVenuesPeriod> list = ticVenuesPeriodService.selectTicVenuesPeriodList(ticVenuesPeriod);
        return getDataTable(list);
    }

    /**
     * 导出方案时间段列表
     */
    @ApiOperation("导出方案时间段列表")
    @RequiresPermissions("ticket:period:export")
    @Log(title = "方案时间段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TicVenuesPeriod ticVenuesPeriod)
    {
        List<TicVenuesPeriod> list = ticVenuesPeriodService.selectTicVenuesPeriodList(ticVenuesPeriod);
        ExcelUtil<TicVenuesPeriod> util = new ExcelUtil<TicVenuesPeriod>(TicVenuesPeriod.class);
        util.exportExcel(response, list, "方案时间段数据");
    }

    /**
     * 获取方案时间段详细信息
     */
    @ApiOperation("获取方案时间段详细信息")
    @RequiresPermissions("ticket:period:query")
    @GetMapping(value = "/{periodId}")
    public AjaxResult getInfo(@PathVariable("periodId") Long periodId)
    {
        return success(ticVenuesPeriodService.selectTicVenuesPeriodByPeriodId(periodId));
    }

    /**
     * 新增方案时间段
     */
    @ApiOperation("新增方案时间段")
    @RequiresPermissions("ticket:period:add")
    @Log(title = "方案时间段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TicVenuesPeriod ticVenuesPeriod)
    {
        return toAjax(ticVenuesPeriodService.insertTicVenuesPeriod(ticVenuesPeriod));
    }

    /**
     * 修改方案时间段
     */
    @ApiOperation("修改方案时间段")
    @RequiresPermissions("ticket:period:edit")
    @Log(title = "方案时间段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TicVenuesPeriod ticVenuesPeriod)
    {
        return toAjax(ticVenuesPeriodService.updateTicVenuesPeriod(ticVenuesPeriod));
    }

    /**
     * 删除方案时间段
     */
    @ApiOperation("删除方案时间段")
    @RequiresPermissions("ticket:period:remove")
    @Log(title = "方案时间段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{periodIds}")
    public AjaxResult remove(@PathVariable Long[] periodIds)
    {
        return toAjax(ticVenuesPeriodService.deleteTicVenuesPeriodByPeriodIds(periodIds));
    }
}
